package com.li.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.li.constant.MessageConstant;
import com.li.entity.PageResult;
import com.li.entity.QueryPageBean;
import com.li.entity.Result;
import com.li.pojo.Member;
import com.li.service.MemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Reference
    private MemberService memberService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pages = memberService.findPage(queryPageBean);
        return pages;
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Member member){

       memberService.add(member);
       return new Result(true, MessageConstant.ADD_MEMBER_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(int id){
        Member me = memberService.findMemberById(id);
        return new Result(true,"",me);

    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Member member){
        memberService.edit(member);
        return new Result(true,MessageConstant.EDIT_MEMBER_SUCCESS);
    }

    @RequestMapping("/delete")
    public Result delete(int id){
        memberService.delete(id);
        return new Result(true,MessageConstant.DELETE_MEMBER_SUCCESS);
    }

}
